package com.mlethe.android.demo.verifycode;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;
import android.widget.TextView;
import android.widget.Toast;

import com.mlethe.android.demo.R;
import com.mlethe.library.widget.verifycode.VerifyCodeView;

public class MainVerifyCodeActivity extends AppCompatActivity implements TextView.OnEditorActionListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_verify_code);
        VerifyCodeView verifyCodeView = findViewById(R.id.verify_code_first);
        VerifyCodeView verifyCodeView2 = findViewById(R.id.verify_code_third);
        verifyCodeView.setOnVerifyCodeListener(new VerifyCodeView.OnVerifyCodeListener() {
            @Override
            public void onFocusChange(VerifyCodeView.EditText editText, boolean hasFocus) {

            }

            @Override
            public void onChanged(VerifyCodeView.EditText editText, int index) {

            }

            @Override
            public void onComplete(String text) {
                Log.e("TAG", "onComplete: " + text);
            }
        });
        verifyCodeView.setImeOptions(EditorInfo.IME_ACTION_SEARCH)
                .setOnEditorActionListener(this);
        verifyCodeView2.setLayoutId(R.layout.verify_test3)
                .setFilledId(R.drawable.border_raduis_blue)
                .setUnfilledId(R.drawable.border_raduis_black);
    }

    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_SEARCH) {
            //do something
            //doSearch();
            Toast.makeText(this, "点击了软键盘的搜索按钮", Toast.LENGTH_SHORT).show();
            return true;
        }
        return false;
    }
}
